package hw1_2;

import java.util.*;
//万能字符串拼写
public class Main {
    public static void main(String[] args) {
        int i;
        int flag =0;
        Scanner scanner = new Scanner(System.in);
        //输入长度
        i = scanner.nextInt();
        //输入单词空格分割
        String[] words = new String[i];
        for (int j = 0; j < i; j++) {
            words[j]=scanner.next();
        }
        //输入掌握的字母
        String chars = scanner.next();
        HashMap<Character, Integer> mapChar = countChar(chars);
        for (String word : words) {
         if(contain(chars,word))flag++;
        }
        System.out.println(flag);
    }
    public static HashMap<Character,Integer> countChar(String s){
        char[] chars = s.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i <chars.length; i++) {
            char c = chars[i];
                map.put(c,map.getOrDefault(c,0)+1);
        }
        return map;
    }

    public static boolean contain(String chars,String word) {
       //判定每个单词是否能掌握
        HashMap<Character, Integer> mapChar = countChar(chars);
        for (char c : word.toCharArray()) {
            //能否在字典中找到
            if(mapChar.containsKey(c)&&mapChar.get(c)>0){
                mapChar.put(c,mapChar.get(c)-1);
            }
            //是否存在万能字符
            else if(mapChar.containsKey('?')&&mapChar.get('?')>0){
                mapChar.put('?', mapChar.get('?')-1);
            }
            else  return false;
        }
        return true;
    }
}
